package com.wyix.entity;

import com.wyix.error.CoffeeBeanNotFoundException;
import com.wyix.error.MilkNotFoundException;

/**
 * @author wangdx
 * @since 2025/8/1
 */
public class CoffeeMachine implements AutoCloseable {

    public void makeCoffee(String type) throws MilkNotFoundException, CoffeeBeanNotFoundException {
        if ("拿铁".equals(type) && !hasMilk()) {
            throw new MilkNotFoundException("牛奶不足，无法制作拿铁");
        }
        if ("美式".equals(type) && !hasCoffeeBean()) {
            throw new CoffeeBeanNotFoundException("咖啡豆不足，无法制作美式");
        }
    }

    private boolean hasCoffeeBean() {
        return false;
    }

    private boolean hasMilk() {
        return false;
    }

    public void clean() {
        System.out.println("清理咖啡机器");
    }

    @Override
    public void close() throws Exception {
        clean();
    }
}
